package it.unibo.util.measures.test.unit;

import static org.junit.Assert.*;

import it.unibo.util.measures.KilometersSecondToMetersSecond;
import it.unibo.util.measures.KilometersToMeters;
import it.unibo.util.measures.KnotsToMetersSecond;
import it.unibo.util.measures.MetersSecondToKilometersSecond;
import it.unibo.util.measures.MetersSecondToKnots;
import it.unibo.util.measures.MetersToKilometers;
import it.unibo.util.measures.MetersToNauticalMiles;
import it.unibo.util.measures.NauticalMilesToMeters;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.BeforeClass;
import org.junit.Test;

public class MeasuresTestCase 
{
	double delta = 0.001;
	static Map<Double,Double> kilometersSecondToMetersSecond = new HashMap<Double, Double>();
	static Map<Double,Double> knotsToMetersSecond = new HashMap<Double, Double>();
	static Map<Double,Double> kilometersToMeters = new HashMap<Double, Double>();
	static Map<Double,Double> nauticalMilesToMeters = new HashMap<Double, Double>();
	
	@BeforeClass
	public static void setUp()
	{
		kilometersSecondToMetersSecond.put(1.0, 1000.0);
		kilometersSecondToMetersSecond.put(10., 10000.0);
		kilometersSecondToMetersSecond.put(45.6, 45600.0);
		
		knotsToMetersSecond.put(1.0, 0.514444444);
		knotsToMetersSecond.put(117.0, 60.19);
		knotsToMetersSecond.put(100.78 , 51.8457111);
		
		kilometersToMeters.put(1.0, 1000.0);
		kilometersToMeters.put(10., 10000.0);
		kilometersToMeters.put(45.6, 45600.0);
		
		nauticalMilesToMeters.put(1.0, 1852.0);
		nauticalMilesToMeters.put(1.0, 1852.0);
		nauticalMilesToMeters.put(100.65, 186403.8);	
	}
	
	@Test
	public void testNauticalMilesToMeters() 
	{
		for (Double kmSec : nauticalMilesToMeters.keySet()) 
		{
			assertEquals(nauticalMilesToMeters.get(kmSec), NauticalMilesToMeters.convert(kmSec), delta);
		}
		
		for (Entry<Double, Double> entry : nauticalMilesToMeters.entrySet()) 
		{
			assertEquals(entry.getKey(), MetersToNauticalMiles.convert(entry.getValue()), delta);
		}
	}
	
	@Test
	public void testKilometersToMeters() 
	{
		for (Double kmSec : kilometersToMeters.keySet()) 
		{
			assertEquals(kilometersToMeters.get(kmSec), KilometersToMeters.convert(kmSec), delta);
		}
		
		for (Entry<Double, Double> entry : kilometersToMeters.entrySet()) 
		{
			assertEquals(entry.getKey(), MetersToKilometers.convert(entry.getValue()), delta);
		}
	}

	@Test
	public void testKilometersSecondToMetersSecond() 
	{
		for (Double kmSec : kilometersSecondToMetersSecond.keySet()) 
		{
			assertEquals(kilometersSecondToMetersSecond.get(kmSec), KilometersSecondToMetersSecond.convert(kmSec), delta);
		}
		
		for (Entry<Double, Double> entry : kilometersSecondToMetersSecond.entrySet()) 
		{
			assertEquals(entry.getKey(), MetersSecondToKilometersSecond.convert(entry.getValue()), delta);
		}
	}
	
	@Test
	public void testKnotsToMetersSecond() 
	{
		for (Double kn : knotsToMetersSecond.keySet()) 
		{
			assertEquals(knotsToMetersSecond.get(kn), KnotsToMetersSecond.convert(kn), delta);
		}
		
		for (Entry<Double, Double> entry : knotsToMetersSecond.entrySet()) 
		{
			assertEquals(entry.getKey(), MetersSecondToKnots.convert(entry.getValue()), delta);
		}
	}

}
